 
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import org.kxml2.*;
import org.kxml2.io.*;
import java.util.*;

/* t1 is the main file for our project and would invoke the
rest of the modules of the project.
*/

public class t1 extends MIDlet  implements CommandListener {

	private Display myDisplay;
	private menuxmlparse menu_xml;
	
	private KrishiMenu k1;
	private OpeningScreen op;
	private Command c1;

	public t1() {

 	//	String []g1_text = {"Bank Schemes" , "Crop Rotation" ,"Soil Analysis" , "Weather" ,"New Tech", "Fertilizer" , "Seed Info" ,"Mill Prices" , "Pest" , "Irrigation" , "Item11"};
	//	String []g1_icon = {"/bank.gif" , "/cropr.jpg" ,"/soil.jpg","/weatherinfo.jpg","/newtech.jpg","/fertilizer.jpg" , "/seeds.jpg","/mill.jpg" , "/pest.jpg" ,"/irig.jpg","/icon1.png","/icon1.png"};
	//	String []g1_audio ={"/alarm.amr", "/alarm.amr" , "/alarm.amr" , "/alarm.amr","/alarm.amr","/alarm.amr","/alarm.amr" ,"/alarm.amr","/alarm.amr","/alarm.amr","/alarm.amr","/alarm.amr"};
		
		Vector kmenu_text = new Vector();
		Vector kmenu_icon =  new Vector();
		Vector kmenu_audio = new Vector();
		int no_of_elem = 0;
		
		// TODO Auto-generated constructor stub
		
		menu_xml = new menuxmlparse(kmenu_text , kmenu_icon , kmenu_audio, no_of_elem, "/krishimenu.xml");
		
		no_of_elem = kmenu_text.capacity();
		
		String []g1_text  = new String[no_of_elem];
		String []g1_icon =  new String[no_of_elem];
		String []g1_audio = new String[no_of_elem];
		
		//System.out.println("Returned Vector Size is = " + kmenu_text.capacity());
		 
		System.out.println(" Number of elements to initialize krishi menu with = " + no_of_elem);
		
		for(int i=0; i < no_of_elem; i++)
		{
			System.out.println("i = " + i);
			g1_text[i] = (String)kmenu_text.elementAt(i);
			g1_icon[i] = (String)kmenu_icon.elementAt(i);
			g1_audio[i] = (String) kmenu_audio.elementAt(i);
			 			
		}
		 
		op = new OpeningScreen();
		k1 = new KrishiMenu(g1_text, g1_icon,g1_audio, 300,300);
		k1.initialize_buttons();
		
		System.out.println(" Name of the text : " + g1_text[0]);
			
		c1 = (Command) new Command("Next", Command.SCREEN , 1);
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO Auto-generated method stub

	}

	protected void pauseApp() {
		// TODO Auto-generated method stub

	}

	protected void startApp() throws MIDletStateChangeException {
		// TODO Auto-generated method stub

		myDisplay=Display.getDisplay(this);
		op.addCommand(c1);
		op.setCommandListener(this);
		k1.setDisplayable(myDisplay); 
		myDisplay.setCurrent(op);
	
		
	}
	
	public void commandAction(Command c , Displayable d)
	{
		if(c == c1)
		{
			myDisplay.setCurrent(k1);
			k1.repaint();
		
		}
	}

}